<?php
$q=$_GET["q"];
$array= explode(",",$q);
$cou_arr=count($array);
$nc="";
$NIC_Number=$array[$cou_arr-1];
$Access_Type=$array[$cou_arr-2];
$AllSchools="";
include_once ("Login/databaseconnection.php");
require_once ("Login/config.php");
$getAllSchools=mysql_query("SELECT DISTINCT(School_Id) FROM school");
while($allsRow=mysql_fetch_array($getAllSchools))
{
if(empty($AllSchools))
{
$AllSchools="'".$allsRow['School_Id']."'";
}
else
{
$AllSchools=$AllSchools.",'".$allsRow['School_Id']."'";
}
}
if($array[1]=="More Than")
{
$oper=">";
}
if($array[1]==">=")
{
$oper=">=";
}
if($array[1]=="Less Than")
{
$oper="<";
}
if($array[1]=="<=")
{
$oper="<=";
}
if($array[1]=="Equal To")
{
$oper="=";
}
if($array[1]!="Equal To"&&$array[1]!="<="&&$array[1]!="Less Than"&&$array[1]!=">="&&$array[1]!="More Than")
{
$oper=$array[1];
}
$hint='<br/><br/><br/>';
if(count($array)!=0)
{
$param="";
$action="";
$sql ="SELECT * FROM resource";
$resulttable = mysql_query($sql);
while ($row=mysql_fetch_array($resulttable))
{
$r=$row['Resource_Type'];
$r_id=$row['Resource_Id'];
$tex="Number of ".$r." in labs";
if($array[0]==$tex)
{
$equ=$r;
$La_Ids="";
$School_Ids="";
if($Access_Type=="Administrator")
	{
$L_ids=mysql_query("SELECT DISTINCT(Lab_Id),School_Id FROM lab WHERE School_Id IN (".$AllSchools.")");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
 	$L_ids=mysql_query("SELECT DISTINCT(Lab_Id) FROM lab WHERE School_Id='$Own_School_Id'");
	}	
	}
	if($L_ids)
	{
  while($rowlid=mysql_fetch_array($L_ids))
  {
$L_Id=$rowlid['Lab_Id'];
$Sc_Id=$rowlid['School_Id'];
$s_id=mysql_query("SELECT COUNT(Resource_Id) As Sum_Id FROM resource_details WHERE Lab_Id='".$L_Id."' AND Resource_Id='".$r_id."' AND School_Id='".$Sc_Id."'");
while($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];

if($Access_Type=="Administrator")
{
$Sc_Id=$rowlid['School_Id'];
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
{
$Sc_Id=$Own_School_Id;
}
if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($La_Ids))
{
$La_Ids=$L_Id;
$School_Ids=$Sc_Id;
}
else
{
$La_Ids=$La_Ids.",".$L_Id;
$School_Ids=$School_Ids.",".$Sc_Id;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($La_Ids))
{
$La_Ids=$L_Id;
$School_Ids=$Sc_Id;
}
else
{
$La_Ids=$La_Ids.",".$L_Id;
$School_Ids=$School_Ids.",".$Sc_Id;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($La_Ids))
{
$La_Ids=$L_Id;
$School_Ids=$Sc_Id;
}
else
{
$La_Ids=$La_Ids.",".$L_Id;
$School_Ids=$School_Ids.",".$Sc_Id;
}
}
}
}
if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($La_Ids))
{
$La_Ids=$L_Id;
$School_Ids=$Sc_Id;
}
else
{
$La_Ids=$La_Ids.",".$L_Id;
$School_Ids=$School_Ids.",".$Sc_Id;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($La_Ids))
{
$La_Ids=$L_Id;
$School_Ids=$Sc_Id;
}
else
{
$La_Ids=$La_Ids.",".$L_Id;
$School_Ids=$School_Ids.",".$Sc_Id;
}
}
}
}
}
$R_La_Ids=explode(",",$La_Ids);
$R_Schoo_Ids=explode(",",$School_Ids);
$nc=count($R_La_Ids);
$param1=$La_Ids.",Lab Id";
$param2=$r_id.",Resource Id";
$param3=$School_Ids.",School Id,resource_details";
$action="triple";
}
}
}


$resultteac = mysql_query("SELECT * FROM teacher");
while ($row=mysql_fetch_array($resultteac))
{
$s=$row['Appointed_Subject'];
$T_NIC_Number=$row['T_NIC_Number'];
$tex="Number of ".$s." teachers in Schools";
if($array[0]==$tex)
{
$app_s=$s;
$Subs="";
if($Access_Type=="Administrator")
	{
$Sc_ids=mysql_query("SELECT DISTINCT(School_Id) FROM school");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Sc_ids=mysql_query("SELECT DISTINCT(School_Id) FROM teacher WHERE School_Id='$Own_School_Id'");
	}
	
	}
	if($Sc_ids)
	{
	$Subs="";
  while($rowlid=mysql_fetch_array($Sc_ids))
  {
$Sch_Id=$rowlid['School_Id'];
$s_id=mysql_query("SELECT COUNT(T_NIC_Number) As Sum_No FROM teacher WHERE School_Id='".$Sch_Id."' AND Appointed_Subject='".$s."'");
if($rowsum = mysql_fetch_array($s_id))
{
$Sum_No=$rowsum['Sum_No'];
	if($oper==">")
{
if($Sum_No>$array[2])
{
if(empty($Subs))
{
$Subs=$Sch_Id;
}
else
{
$Subs=$Subs.",".$Sch_Id;
}
}
}
	if($oper==">=")
{
if($Sum_No>=$array[2])
{
if(empty($Subs))
{
$Subs=$Sch_Id;
}
else
{
$Subs=$Subs.",".$Sch_Id;
}
}
}
if($oper=="<")
{
if($Sum_No<=0&&$array[2]>0)
{
}
else
{
if($Sum_No<$array[2])
{
if(empty($Subs))
{
$Subs=$Sch_Id;
}
else
{
$Subs=$Subs.",".$Sch_Id;
}
}
}
}

if($oper=="<=")
{
if($Sum_No<=0&&$array[2]>0)
{
}
else
{
if($Sum_No<=$array[2])
{
if(empty($Subs))
{
$Subs=$Sch_Id;
}
else
{
$Subs=$Subs.",".$Sch_Id;
}
}
}
}
	if($oper=="=")
{
if($Sum_No==$array[2])
{
if(empty($$Subs))
{
$$Subs=$Sch_Id;
}
else
{
$Subs=$Subs.",".$Sch_Id;
}
}
}

}
}
$A_Subs=explode(",",$Subs);
$nc=count($A_Subs);
$param=$Subs.",School Id,teacher";		
$action="double";
}
}
}
if($array[0]=="Won times of Competitions")
{
$CScho_Ids="";
$Com_Id="";
$Dat="";
if($Access_Type=="Administrator")
	{
	$Sc_ids=mysql_query("SELECT DISTINCT(School_Id) FROM competition WHERE School_Id IN (".$AllSchools.")");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Sc_ids=mysql_query("SELECT DISTINCT(School_Id) FROM competition WHERE School_Id='$Own_School_Id'");
	}
	
	}
	if($Sc_ids)
	{
  while($rowlid=mysql_fetch_array($Sc_ids))
  {
$School_Id=$rowlid['School_Id'];
$s_id=mysql_query("SELECT COUNT(Result) As Sum_Id FROM competition WHERE School_Id='".$School_Id."' AND Result='Win'");
if($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];
	if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($CScho_Ids))
{
$CScho_Ids=$School_Id;
$Times=$Sum_Id;
}
else
{
$CScho_Ids=$CScho_Ids.",".$School_Id;
$Times=$Times.",".$Sum_Id;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($CScho_Ids))
{
$CScho_Ids=$School_Id;
$Times=$Sum_Id;
}
else
{
$CScho_Ids=$CScho_Ids.",".$School_Id;
$Times=$Times.",".$Sum_Id;
}
}
}
if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($CScho_Ids))
{
$CScho_Ids=$School_Id;
$Times=$Sum_Id;
}
else
{
$CScho_Ids=$CScho_Ids.",".$School_Id;
$Times=$Times.",".$Sum_Id;
}
}
}
}
if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($CScho_Ids))
{
$CScho_Ids=$School_Id;
$Times=$Sum_Id;
}
else
{
$CScho_Ids=$CScho_Ids.",".$School_Id;
$Times=$Times.",".$Sum_Id;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($CScho_Ids))
{
$CScho_Ids=$School_Id;
$Times=$Sum_Id;
}
else
{
$CScho_Ids=$CScho_Ids.",".$School_Id;
$Times=$Times.",".$Sum_Id;
}
}
}
}
}
$CSchoo_Ids=explode(",",$CScho_Ids);
$Timesc=explode(",",$Times);
$nc=count($CSchoo_Ids);
$param1=$CScho_Ids.",School Id";
$param2=$Times.",Winned Times,competition";
$action="double";
}
}
if($array[0]=="Training duration of trained teachers")
{
$T_Nics="";
$Tra_Id="";
$Sc_ids=mysql_query("SELECT * FROM training_details");
  while($rowlid=mysql_fetch_array($Sc_ids))
  {
$Teacher_NIC=$rowlid['Teacher_NIC'];
$dura=$rowlid['Duration'];
$Training_Id=$rowlid['Training_Id'];
$T_len=strlen($dura);
$year = strstr($dura,"Y");
$yearsm = strstr($dura,"y");
if($year!=""&&$year!=$dura)
{
$len=strlen($year);
$f_len=$T_len-$len;
$Sum_Id=substr($dura,0,$f_len);
}
if($yearsm!=""&&$yearsm!=$dura)
{
$len=strlen($yearsm);
$f_len=$T_len-$len;
$Sum_Id=substr($dura,0,$f_len);
}
if($year==""&&$yearsm=="")
{
$Sum_Id=$dura;
}
$T_len2=strlen($array[2]);
$year2 = strstr ($array[2], "Y");
$yearsm2 = strstr ($array[2], "y");
if($year2!=""&&$year2!=$array[2])
{
$len2=strlen($year2);
$f_len2=$T_len2-$len2;
$array2=substr($array[2],0,$f_len2);
}
if($yearsm2!=""&&$yearsm2!=$array[2])
{
$len2=strlen($yearsm2);
$f_len2=$T_len2-$len2;
$array2=substr($array[2],0,$f_len2);
}
if($year2==""&&$yearsm2=="")
{
$array2=$array[2];
}

if($oper==">")
{
if($Sum_Id>$array2)
{
if(empty($T_Nics))
{
if($Access_Type=="Administrator")
	{
$T_Nics=$Teacher_NIC;
$Tra_Id=$Training_Id;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$Teacher_NIC'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['Teacher_NIC']==$Teacher_NIC)
	{
$T_Nics=$Teacher_NIC;
$Tra_Id=$Training_Id;
}
}
}
	}
	
	}

}
else
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_Nics.",".$Teacher_NIC;
$Tra_Id=$Tra_Id.",".$Training_Id;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$Teacher_NIC'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['Teacher_NIC']==$Teacher_NIC)
	{
$T_Nics=$T_Nics.",".$Teacher_NIC;
$Tra_Id=$Tra_Id.",".$Training_Id;
}
}
}
	}
	
	}

}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array2)
{
if(empty($T_Nics))
{
$T_Nics=$Teacher_NIC;
$Tra_Id=$Training_Id;
}
else
{
$T_Nics=$T_Nics.",".$Teacher_NIC;
$Tra_Id=$Tra_Id.",".$Training_Id;
}
}
}
if($oper=="<")
{
if($Sum_Id<=0&&$array2>0)
{
}
else
{
if($Sum_Id<$array2)
{
if(empty($T_Nics))
{
if($Access_Type=="Administrator")
	{
$T_Nics=$Teacher_NIC;
$Tra_Id=$Training_Id;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$Teacher_NIC'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['Teacher_NIC']==$Teacher_NIC)
	{
$T_Nics=$Teacher_NIC;
$Tra_Id=$Training_Id;
}
}
}
	}
	}

}
else
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_Nics.",".$Teacher_NIC;
$Tra_Id=$Tra_Id.",".$Training_Id;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$Teacher_NIC'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['Teacher_NIC']==$Teacher_NIC)
	{
$T_Nics=$T_Nics.",".$Teacher_NIC;
$Tra_Id=$Tra_Id.",".$Training_Id;
}
}
}
	}
	
	}
}
}
}
}
if($oper=="<=")
{
if($Sum_Id<=0&&$array2>0)
{
}
else
{
if($Sum_Id<=$array2)
{
if(empty($T_Nics))
{
if($Access_Type=="Administrator")
	{
$T_Nics=$Teacher_NIC;
$Tra_Id=$Training_Id;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$Teacher_NIC'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['Teacher_NIC']==$Teacher_NIC)
	{
$T_Nics=$Teacher_NIC;
$Tra_Id=$Training_Id;
}
}
}
	}
	
	}

}
else
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_Nics.",".$Teacher_NIC;
$Tra_Id=$Tra_Id.",".$Training_Id;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$Teacher_NIC'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['Teacher_NIC']==$Teacher_NIC)
	{
$T_Nics=$T_Nics.",".$Teacher_NIC;
$Tra_Id=$Tra_Id.",".$Training_Id;
}
}
}
	}
	
	}

}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array2)
{
if(empty($T_Nics))
{
if($Access_Type=="Administrator")
	{
$T_Nics=$Teacher_NIC;
$Tra_Id=$Training_Id;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$Teacher_NIC'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['Teacher_NIC']==$Teacher_NIC)
	{
$T_Nics=$Teacher_NIC;
$Tra_Id=$Training_Id;
}
}
}
	}
	
	}

}
else
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_Nics.",".$Teacher_NIC;
$Tra_Id=$Tra_Id.",".$Training_Id;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE Teacher_NIC='$Teacher_NIC'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['Teacher_NIC']==$Teacher_NIC)
	{
$T_Nics=$T_Nics.",".$Teacher_NIC;
$Tra_Id=$Tra_Id.",".$Training_Id;
}
}
}
	}
	
	}

}
}
}
}
$Teac_Nics=explode(",",$T_Nics);
$Trai_Id=explode(",",$Tra_Id);
$nc=count($Teac_Nics);
$param1=$T_Nics.",Teacher NIC";
$param2=$Tra_Id.",Training Id,training_details";
$action="double";
}

if($array[0]=="Service period of teachers")
{
$T_Nics="";
$Sc_ids=mysql_query("SELECT * FROM teacher");
  while($rowlid=mysql_fetch_array($Sc_ids))
  {
$T_NIC_Number=$rowlid['T_NIC_Number'];
$Ser_Pe=$rowlid['Service'];
$T_len=strlen($Ser_Pe);
$year = strstr ($Ser_Pe, "Y");
$yearsm = strstr ($Ser_Pe, "y");
if($year!=""&&$year!=$Ser_Pe)
{
$len=strlen($year);
$f_len=$T_len-$len;
$Sum_Id=substr($Ser_Pe,0,$f_len);
}
if($yearsm!=""&&$yearsm!=$Ser_Pe)
{
$len=strlen($yearsm);
$f_len=$T_len-$len;
$Sum_Id=substr($Ser_Pe,0,$f_len);
}
if($year==""&&$yearsm=="")
{
$Sum_Id=0;
}
$T_len2=strlen($array[2]);
$year2 = strstr ($array[2], "Y");
$yearsm2 = strstr ($array[2], "y");
if($year2!=""&&$year2!=$array[2])
{
$len2=strlen($year2);
$f_len2=$T_len2-$len2;
$array2=substr($array[2],0,$f_len2);
}
if($yearsm2!=""&&$yearsm2!=$array[2])
{
$len2=strlen($yearsm2);
$f_len2=$T_len2-$len2;
$array2=substr($array[2],0,$f_len2);
}
if($year2==""&&$yearsm2=="")
{
$array2=$array[2];
}
	if($oper==">")
{
if($Sum_Id>$array2)
{
if(empty($T_Nics))
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_NIC_Number;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['T_NIC_Number']==$T_NIC_Number)
	{
$T_Nics=$T_NIC_Number;
}
}
}
	}
	
	}

}
else
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_Nics.",".$T_NIC_Number;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['T_NIC_Number']==$T_NIC_Number)
	{
$T_Nics=$T_Nics.",".$T_NIC_Number;
}
}
}
	}
	
	}

}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array2)
{
if(empty($T_Nics))
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_NIC_Number;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['T_NIC_Number']==$T_NIC_Number)
	{
$T_Nics=$T_NIC_Number;
}
}
}
	}
	
	}

}
else
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_Nics.",".$T_NIC_Number;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['T_NIC_Number']==$T_NIC_Number)
	{
$T_Nics=$T_Nics.",".$T_NIC_Number;
}
}
}
	}
	
	}

}
}
}
if($oper=="<")
{
if($Sum_Id<=0&&$array2>0)
{
}
else
{
if($Sum_Id<$array2)
{
if(empty($T_Nics))
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_NIC_Number;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['T_NIC_Number']==$T_NIC_Number)
	{
$T_Nics=$T_NIC_Number;
}
}
}
	}
	
	}

}
else
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_Nics.",".$T_NIC_Number;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['T_NIC_Number']==$T_NIC_Number)
	{
$T_Nics=$T_Nics.",".$T_NIC_Number;
}
}
}
	}
	
	}

}
}
}
}
	if($oper=="<=")
{
if($Sum_Id<=0&&$array2>0)
{
}
else
{
if($Sum_Id<=$array2)
{
if(empty($T_Nics))
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_NIC_Number;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['T_NIC_Number']==$T_NIC_Number)
	{
$T_Nics=$T_NIC_Number;
}
}
}
	}
	
	}

}
else
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_Nics.",".$T_NIC_Number;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['T_NIC_Number']==$T_NIC_Number)
	{
$T_Nics=$T_Nics.",".$T_NIC_Number;
}
}
}
	}
	
	}

}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array2)
{
if(empty($T_Nics))
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_NIC_Number;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['T_NIC_Number']==$T_NIC_Number)
	{
$T_Nics=$T_NIC_Number;
}
}
}
	}
	
	}

}
else
{
if($Access_Type=="Administrator")
	{
$T_Nics=$T_Nics.",".$T_NIC_Number;
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Che_Sc_ids=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$T_NIC_Number'");
	if($Che_Sc_ids)
	{
	if($rcheck=mysql_fetch_array($Che_Sc_ids))
	{
	if($rcheck['T_NIC_Number']==$T_NIC_Number)
	{
$T_Nics=$T_Nics.",".$T_NIC_Number;
}
}
}
	}
	
	}

}
}
}
}
$Tea_Nics=explode(",",$T_Nics);
$nc=count($Tea_Nics);
$param=$T_Nics.",T NIC Number,teacher";
$action="single";
}

if($array[0]=="Number of Teachers in Training for Programmes")
{
$P_Ids="";
if($Access_Type=="Administrator")
	{
$Sc_ids=mysql_query("SELECT * FROM programmes");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Sc_ids=mysql_query("SELECT * FROM programmes WHERE School_Id='$Own_School_Id'");
	}
	
	}
	if($Sc_ids)
	{
  while($rowlid=mysql_fetch_array($Sc_ids))
  {
$Programme_Id=$rowlid['Programme_Id'];
$School_Id=$rowlid['School_Id'];
$Sum_Id=$rowlid['Teachers_In_Training'];
	if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$Ps_Ids=$Ps_Ids.",".$School_Id;
$P_Ids=$P_Ids.",".$Programme_Id;
}
}
}
}
	if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
}
$Pro_Ids=explode(",",$P_Ids);
$Psch_Ids=explode(",",$Ps_Ids);
$nc=count($Pro_Ids);
$param1=$P_Ids.",Programme Id";
$param2=$Ps_Ids.",School Id,programmes";
$action="double";
}
}
if($array[0]=="Number of Trained Teachers for Programmes")
{
$P_Ids="";
if($Access_Type=="Administrator")
	{
$Sc_ids=mysql_query("SELECT * FROM programmes");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Sc_ids=mysql_query("SELECT * FROM programmes WHERE School_Id='$Own_School_Id'");
	}
	
	}
	if($Sc_ids)
	{
  while($rowlid=mysql_fetch_array($Sc_ids))
  {
$Programme_Id=$rowlid['Programme_Id'];
$School_Id=$rowlid['School_Id'];
$Sum_Id=$rowlid['Trained_Teachers'];
	if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$Ps_Ids=$Ps_Ids.",".$School_Id;
$P_Ids=$P_Ids.",".$Programme_Id;
}
}
}
}
	if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
}
$Pro_Ids=explode(",",$P_Ids);
$Psch_Ids=explode(",",$Ps_Ids);
$nc=count($Pro_Ids);
$param1=$P_Ids.",Programme Id";
$param2=$Ps_Ids.",School Id,programmes";
$action="double";
}
}
if($array[0]=="Number of Students for Programmes")
{
$P_Ids="";
if($Access_Type=="Administrator")
{
$Sc_ids=mysql_query("SELECT * FROM programmes");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='".$NIC_Number."'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $Sc_ids=mysql_query("SELECT * FROM programmes WHERE School_Id='".$Own_School_Id."'");
}
	}
	if($Sc_ids)
	{
  while($rowlid=mysql_fetch_array($Sc_ids))
  {
$Programme_Id=$rowlid['Programme_Id'];
$School_Id=$rowlid['School_Id'];
$Sum_Id=$rowlid['No_Of_Female_Students']+$rowlid['No_Of_Male_Students'];
	if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
}
	if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($P_Ids))
{
$P_Ids=$Programme_Id;
$Ps_Ids=$School_Id;
}
else
{
$P_Ids=$P_Ids.",".$Programme_Id;
$Ps_Ids=$Ps_Ids.",".$School_Id;
}
}
}
}
$Pro_Ids=explode(",",$P_Ids);
$Psch_Ids=explode(",",$Ps_Ids);
$nc=count($Pro_Ids);
$param1=$P_Ids.",Programme Id";
$param2=$Ps_Ids.",School Id,programmes";
$action="double";
}
}
if($array[0]=="Number of Teachers in Schools")
{
$Scho_Ids="";
if($Access_Type=="Administrator")
	{
$Sc_ids=mysql_query("SELECT DISTINCT(School_Id) FROM teacher");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 	$Sc_ids=mysql_query("SELECT DISTINCT(School_Id) FROM teacher WHERE School_Id='$Own_School_Id'");
	}
	
	}
	if($Sc_ids)
	{
  while($rowlid=mysql_fetch_array($Sc_ids))
  {
$School_Id=$rowlid['School_Id'];
$s_id=mysql_query("SELECT COUNT(T_NIC_Number) As Sum_Id FROM teacher WHERE School_Id='".$School_Id."'");
if($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];
	if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($Scho_Ids))
{
$Scho_Ids=$School_Id;
}
else
{
$Scho_Ids=$Scho_Ids.",".$School_Id;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($Scho_Ids))
{
$Scho_Ids=$School_Id;
}
else
{
$Scho_Ids=$Scho_Ids.",".$School_Id;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($Scho_Ids))
{
$Scho_Ids=$School_Id;
}
else
{
$Scho_Ids=$Scho_Ids.",".$School_Id;
}
}
}
}
	if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($Scho_Ids))
{
$Scho_Ids=$School_Id;
}
else
{
$Scho_Ids=$Scho_Ids.",".$School_Id;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($Scho_Ids))
{
$Scho_Ids=$School_Id;
}
else
{
$Scho_Ids=$Scho_Ids.",".$School_Id;
}
}
}
}
}
$Schoo_Ids=explode(",",$Scho_Ids);
$nc=count($Schoo_Ids);
$action="single";
$param=$Scho_Ids.",School Id,teacher";
}
}
if($array[0]=="Number of Students in Schools")
{
$Stu="";
if($Access_Type=="Administrator")
	{
$Sc_ids=mysql_query("SELECT * FROM school");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 $Sc_ids=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
	}
	
	}
	if($Sc_ids)
	{
  while($rowlid=mysql_fetch_array($Sc_ids))
  {
$School_Id=$rowlid['School_Id'];
$m_s=$rowlid['Male_Students'];
$f_s=$rowlid['Female_Students'];
$t_s=$m_s+$f_s;
	if($oper==">")
{
if($t_s>$array[2])
{
if(empty($Stu))
{
$Stu=$School_Id;
}
else
{
$Stu=$Stu.",".$School_Id;
}
}
}
	if($oper==">=")
{
if($t_s>=$array[2])
{
if(empty($Stu))
{
$Stu=$School_Id;
}
else
{
$Stu=$Stu.",".$School_Id;
}
}
}
	if($oper=="<")
{
if($t_s<=0&&$array[2]>0)
{
}
else
{
if($t_s<$array[2])
{
if(empty($Stu))
{
$Stu=$School_Id;
}
else
{
$Stu=$Stu.",".$School_Id;
}
}
}
}
	if($oper=="<=")
{
if($t_s<=0&&$array[2]>0)
{
}
else
{
if($t_s<=$array[2])
{
if(empty($Stu))
{
$Stu=$School_Id;
}
else
{
$Stu=$Stu.",".$School_Id;
}
}
}
}
	if($oper=="=")
{
if($t_s==$array[2])
{
if(empty($Stu))
{
$Stu=$School_Id;
}
else
{
$Stu=$Stu.",".$School_Id;
}
}
}
}
$Stud=explode(",",$Stu);
$nc=count($Stud);
$param=$Stu.",School Id,school";
$action="single";
}
}
if($array[0]=="Number of Labs")
{
$Scho_Ids="";
if($Access_Type=="Administrator")
	{
$Sc_ids=mysql_query("SELECT DISTINCT(School_Id) FROM school");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
 $Sc_ids=mysql_query("SELECT DISTINCT(School_Id) FROM lab WHERE School_Id='$Own_School_Id'");
	}	
	}
	if($Sc_ids)
	{
  while($rowlid=mysql_fetch_array($Sc_ids))
  {
$School_Id=$rowlid['School_Id'];
$s_id=mysql_query("SELECT COUNT(Lab_Id) As Sum_Id FROM lab WHERE School_Id='".$School_Id."'");
if($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];
	if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($Scho_Ids))
{
$Scho_Ids=$School_Id;
}
else
{
$Scho_Ids=$Scho_Ids.",".$School_Id;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($Scho_Ids))
{
$Scho_Ids=$School_Id;
}
else
{
$Scho_Ids=$Scho_Ids.",".$School_Id;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($Scho_Ids))
{
$Scho_Ids=$School_Id;
}
else
{
$Scho_Ids=$Scho_Ids.",".$School_Id;
}
}
}
}
	if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($Scho_Ids))
{
$Scho_Ids=$School_Id;
}
else
{
$Scho_Ids=$Scho_Ids.",".$School_Id;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($Scho_Ids))
{
$Scho_Ids=$School_Id;
}
else
{
$Scho_Ids=$Scho_Ids.",".$School_Id;
}
}
}
}
}
$Schoo_Ids=explode(",",$Scho_Ids);
$nc=count($Schoo_Ids);
$param=$Scho_Ids.",School Id,lab";
$action="single";
}
}

$sql_Con =mysql_query("SELECT DISTINCT(Congeniality) FROM school");
while ($row=mysql_fetch_array($sql_Con))
{
$c=$row['Congeniality'];
$tex="Number of ".$c." schools in Zones";
if($array[0]==$tex)
{
$con=$c;
$Zones="";
if($Access_Type=="Administrator")
	{
$Schs=mysql_query("SELECT DISTINCT(Zone) FROM school WHERE Congeniality='".$con."'");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	$z=mysql_query("SELECT Zone FROM school WHERE School_Id='".$Own_School_Id."'");
	if($r_z=mysql_fetch_array($z))
	{
	$o_z=$r_z['Zone'];
	}
 	$Schs=mysql_query("SELECT Zone FROM school WHERE Congeniality='".$con."' Zone='$o_z'");
	}	
	}
	if($Schs)
	{
  while($row_sch=mysql_fetch_array($Schs))
  {
$Zone=$row_sch['Zone'];
$s_id=mysql_query("SELECT COUNT(Census_Number) As Sum_Id FROM school WHERE Zone='".$Zone."' AND Congeniality='".$con."'");
while($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];

if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
}
if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
}
}
$R_Zones=explode(",",$Zones);
$nc=count($R_Zones);
$param1=$Zones.",Zone";
$param2=$con.",Congeniality,school";
$action="double";
}
}
}

$sql_Ethi =mysql_query("SELECT DISTINCT(Ethinicity) FROM school");
while ($row=mysql_fetch_array($sql_Ethi))
{
$e=$row['Ethinicity'];
$tex="Number of ".$e." schools in Zones";
if($array[0]==$tex)
{
$Ethi=$e;
$Zones="";
if($Access_Type=="Administrator")
	{
$Schs=mysql_query("SELECT DISTINCT(Zone) FROM school WHERE Ethinicity='".$Ethi."'");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	$z=mysql_query("SELECT Zone FROM school WHERE School_Id='".$Own_School_Id."'");
	if($r_z=mysql_fetch_array($z))
	{
	$o_z=$r_z['Zone'];
	}
 	$Schs=mysql_query("SELECT Zone FROM school WHERE Ethinicity='".$Ethi."' Zone='$o_z'");
	}	
	}
	if($Schs)
	{
  while($row_sch=mysql_fetch_array($Schs))
  {
$Zone=$row_sch['Zone'];
$s_id=mysql_query("SELECT COUNT(Census_Number) As Sum_Id FROM school WHERE Zone='".$Zone."' AND Ethinicity='".$Ethi."'");
while($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];

if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
}
if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
}
}
$R_Zones=explode(",",$Zones);
$nc=count($R_Zones);
$param1=$Zones.",Zone";
$param2=$Ethi.",Ethinicity,school";
$action="double";
}
}
}

$sql_Func =mysql_query("SELECT DISTINCT(Function) FROM school");
while ($row=mysql_fetch_array($sql_Func))
{
$f=$row['Function'];
$tex="Number of ".$f." schools in Zones";
if($array[0]==$tex)
{
$Func=$f;
$Zones="";
if($Access_Type=="Administrator")
	{
$Schs=mysql_query("SELECT DISTINCT(Zone) FROM school WHERE Function='".$Func."'");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	$z=mysql_query("SELECT Zone FROM school WHERE School_Id='".$Own_School_Id."'");
	if($r_z=mysql_fetch_array($z))
	{
	$o_z=$r_z['Zone'];
	}
 	$Schs=mysql_query("SELECT Zone FROM school WHERE Function='".$Func."' Zone='$o_z'");
	}	
	}
	if($Schs)
	{
  while($row_sch=mysql_fetch_array($Schs))
  {
$Zone=$row_sch['Zone'];
$s_id=mysql_query("SELECT COUNT(Census_Number) As Sum_Id FROM school WHERE Zone='".$Zone."' AND Function='".$Func."'");
while($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];

if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
}
if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($Zones))
{
$Zones=$Zone;
}
else
{
$Zones=$Zones.",".$Zone;
}
}
}
}
}
$R_Zones=explode(",",$Zones);
$nc=count($R_Zones);
$param1=$Zones.",Zone";
$param2=$Func.",Function,school";
$action="double";
}
}
}

$sql_lc =mysql_query("SELECT DISTINCT(Lab_Category) FROM lab");
while ($row=mysql_fetch_array($sql_lc))
{
$lc=$row['Lab_Category'];
$tex="Number of ".$lc." labs in Schools";
if($array[0]==$tex)
{
$l_cat=$lc;
$Category_Sch_Ids="";
if($Access_Type=="Administrator")
	{
$Schs=mysql_query("SELECT DISTINCT(School_Id) FROM lab WHERE Lab_Category='".$l_cat."'");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	$Schs=mysql_query("SELECT * FROM lab WHERE Lab_Category='".$l_cat."' School_Id='$Own_School_Id'");
	}	
	}
	if($Schs)
	{
  while($row_sch=mysql_fetch_array($Schs))
  {
$S_ID=$row_sch['School_Id'];
$s_id=mysql_query("SELECT COUNT(Lab_Id) As Sum_Id FROM lab WHERE School_Id='".$S_ID."' AND Lab_Category='".$l_cat."'");
while($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];

if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($Category_Sch_Ids))
{
$Category_Sch_Ids=$S_ID;
}
else
{
$Category_Sch_Ids=$Category_Sch_Ids.",".$S_ID;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($Category_Sch_Ids))
{
$Category_Sch_Ids=$S_ID;
}
else
{
$Category_Sch_Ids=$Category_Sch_Ids.",".$S_ID;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($Category_Sch_Ids))
{
$Category_Sch_Ids=$S_ID;
}
else
{
$Category_Sch_Ids=$Category_Sch_Ids.",".$S_ID;
}
}
}
}
if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($Category_Sch_Ids))
{
$Category_Sch_Ids=$S_ID;
}
else
{
$Category_Sch_Ids=$Category_Sch_Ids.",".$S_ID;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($Category_Sch_Ids))
{
$Category_Sch_Ids=$S_ID;
}
else
{
$Category_Sch_Ids=$Category_Sch_Ids.",".$S_ID;
}
}
}
}
}
$R_Lab_Sch_Ids=explode(",",$Category_Sch_Ids);
$nc=count($R_Lab_Sch_Ids);
$param1=$Category_Sch_Ids.",School Id";
$param2=$l_cat.",Lab Category,lab";
$action="double";
}
}
}

$sql_lt =mysql_query("SELECT DISTINCT(Lab_Type) FROM lab");
while ($row=mysql_fetch_array($sql_lt))
{
$lt=$row['Lab_Type'];
$tex="Number of ".$lt."s in Schools";
if($array[0]==$tex)
{
$l_type=$lt;
$L_Type_Sch_Ids="";
if($Access_Type=="Administrator")
	{
$Schs=mysql_query("SELECT DISTINCT(School_Id) FROM lab WHERE Lab_Type='".$l_type."'");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	$Schs=mysql_query("SELECT * FROM lab WHERE Lab_Type='".$l_type."' School_Id='$Own_School_Id'");
	}	
	}
	if($Schs)
	{
  while($row_sch=mysql_fetch_array($Schs))
  {
$S_ID=$row_sch['School_Id'];
$s_id=mysql_query("SELECT COUNT(Lab_Id) As Sum_Id FROM lab WHERE School_Id='".$S_ID."' AND Lab_Type='".$l_type."'");
while($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];

if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($L_Type_Sch_Ids))
{
$L_Type_Sch_Ids=$S_ID;
}
else
{
$L_Type_Sch_Ids=$L_Type_Sch_Ids.",".$S_ID;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($L_Type_Sch_Ids))
{
$L_Type_Sch_Ids=$S_ID;
}
else
{
$L_Type_Sch_Ids=$L_Type_Sch_Ids.",".$S_ID;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($L_Type_Sch_Ids))
{
$L_Type_Sch_Ids=$S_ID;
}
else
{
$L_Type_Sch_Ids=$L_Type_Sch_Ids.",".$S_ID;
}
}
}
}
if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($L_Type_Sch_Ids))
{
$L_Type_Sch_Ids=$S_ID;
}
else
{
$L_Type_Sch_Ids=$L_Type_Sch_Ids.",".$S_ID;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($L_Type_Sch_Ids))
{
$L_Type_Sch_Ids=$S_ID;
}
else
{
$L_Type_Sch_Ids=$L_Type_Sch_Ids.",".$S_ID;
}
}
}
}
}
$R_Lab_Sch_Ids=explode(",",$L_Type_Sch_Ids);
$nc=count($R_Lab_Sch_Ids);
$param1=$L_Type_Sch_Ids.",School Id";
$param2=$l_type.",Lab Type,lab";
$action="double";
}
}
}

$sqlsp =mysql_query("SELECT DISTINCT(Specialised_In) FROM teacher");
while ($row=mysql_fetch_array($sqlsp))
{
$sp=$row['Specialised_In'];
$tex="Number of ".$sp." specialised teachers in Schools";
if($array[0]==$tex)
{
$specialised_in=$sp;
$S_In_Sch_Ids="";
if($Access_Type=="Administrator")
	{
$Schs=mysql_query("SELECT * FROM teacher WHERE Specialised_In='".$specialised_in."'");
}
else if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
	{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	$Schs=mysql_query("SELECT * FROM teacher WHERE Specialised_In='".$specialised_in."' School_Id='$Own_School_Id'");
	}	
	}
	if($Schs)
	{
  while($row_sch=mysql_fetch_array($Schs))
  {
$S_ID=$row_sch['School_Id'];
$s_id=mysql_query("SELECT COUNT(Lab_Id) As Sum_Id FROM teacher WHERE School_Id='".$S_ID."' AND Specialised_In='".$specialised_in."'");
while($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];

if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($S_In_Sch_Ids))
{
$S_In_Sch_Ids=$S_ID;
}
else
{
$S_In_Sch_Ids=$S_In_Sch_Ids.",".$S_ID;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($S_In_Sch_Ids))
{
$S_In_Sch_Ids=$S_ID;
}
else
{
$S_In_Sch_Ids=$S_In_Sch_Ids.",".$S_ID;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($S_In_Sch_Ids))
{
$S_In_Sch_Ids=$S_ID;
}
else
{
$S_In_Sch_Ids=$S_In_Sch_Ids.",".$S_ID;
}
}
}
}
if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($S_In_Sch_Ids))
{
$S_In_Sch_Ids=$S_ID;
}
else
{
$S_In_Sch_Ids=$S_In_Sch_Ids.",".$S_ID;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($S_In_Sch_Ids))
{
$S_In_Sch_Ids=$S_ID;
}
else
{
$S_In_Sch_Ids=$S_In_Sch_Ids.",".$S_ID;
}
}
}
}
}
$R_S_In_Sch_Ids=explode(",",$S_In_Sch_Ids);
$nc=count($R_S_In_Sch_Ids);
$param1=$S_In_Sch_Ids.",School Id";
$param2=$specialised_in.",Specialised In,teacher";
$action="double";
}
}
}

$sql_t =mysql_query("SELECT DISTINCT(Training_Id) FROM training_details");
while ($row=mysql_fetch_array($sql_t))
{
$t_id=$row['Training_Id'];
$tra_name=mysql_query("SELECT Training_Name FROM training WHERE Training_Id='".$t_id."'");
if($row_tra_name=mysql_fetch_array($tra_name))
{
$Tra_Name=$row_tra_name['Training_Name'];
}
$tex="Number of ".$Tra_Name." trained teachers in Schools";
if($array[0]==$tex)
{
$Tra_Id=$t_id;
$Tra_Sch_Ids="";
if($Access_Type=="Teacher"||$Access_Type=="Teacher in Charge")
{
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
    $Own_School_Id=$rowsch['School_Id'];
	$All_Teacher_NIC="";
$all_schs=mysql_query("SELECT T_NIC_Number FROM teacher WHERE School_Id='".$Own_School_Id."'");
while($row_all_schs=mysql_fetch_array($all_schs))
{
if(empty($All_Teacher_NIC))
{
$All_Teacher_NIC="'".$row_all_schs['T_NIC_Number']."'";
}
else
{
$All_Teacher_NIC=$All_Teacher_NIC.",'".$row_all_schs['T_NIC_Number']."'";
}
}
if($All_Teacher_NIC!="")
{
$S_ID=$Own_School_Id;
$s_id=mysql_query("SELECT COUNT(Teacher_NIC) As Sum_Id FROM training_details WHERE Teacher_NIC IN(".$All_Teacher_NIC.") AND Training_Id='".$Tra_Id."'");
while($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];

if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($Tra_Sch_Ids))
{
$Tra_Sch_Ids=$S_ID;
}
else
{
$Tra_Sch_Ids=$Tra_Sch_Ids.",".$S_ID;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($Tra_Sch_Ids))
{
$Tra_Sch_Ids=$S_ID;
}
else
{
$Tra_Sch_Ids=$Tra_Sch_Ids.",".$S_ID;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($Tra_Sch_Ids))
{
$Tra_Sch_Ids=$S_ID;
}
else
{
$Tra_Sch_Ids=$Tra_Sch_Ids.",".$S_ID;
}
}
}
}
if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($Tra_Sch_Ids))
{
$Tra_Sch_Ids=$S_ID;
}
else
{
$Tra_Sch_Ids=$Tra_Sch_Ids.",".$S_ID;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($Tra_Sch_Ids))
{
$Tra_Sch_Ids=$S_ID;
}
else
{
$Tra_Sch_Ids=$Tra_Sch_Ids.",".$S_ID;
}
}
}
}
}
	}	
	}
if($Access_Type=="Administrator")
{
$a_s=mysql_query("SELECT * FROM School");
while($row_a_s=mysql_fetch_array($a_s))
{
$All_Teacher_NIC="";
$all_schs=mysql_query("SELECT T_NIC_Number FROM teacher WHERE School_Id='".$row_a_s['School_Id']."'");
while($row_all_schs=mysql_fetch_array($all_schs))
{
if(empty($All_Teacher_NIC))
{
$All_Teacher_NIC="'".$row_all_schs['T_NIC_Number']."'";
}
else
{
$All_Teacher_NIC=$All_Teacher_NIC.",'".$row_all_schs['T_NIC_Number']."'";
}
}

if($All_Teacher_NIC!="")
{
$S_ID=$row_a_s['School_Id'];
$s_id=mysql_query("SELECT COUNT(Teacher_NIC) As Sum_Id FROM training_details WHERE Teacher_NIC IN(".$All_Teacher_NIC.") AND Training_Id='".$Tra_Id."'");
while($rowsum = mysql_fetch_array($s_id))
{
$Sum_Id=$rowsum['Sum_Id'];

if($oper==">")
{
if($Sum_Id>$array[2])
{
if(empty($Tra_Sch_Ids))
{
$Tra_Sch_Ids=$S_ID;
}
else
{
$Tra_Sch_Ids=$Tra_Sch_Ids.",".$S_ID;
}
}
}
	if($oper==">=")
{
if($Sum_Id>=$array[2])
{
if(empty($Tra_Sch_Ids))
{
$Tra_Sch_Ids=$S_ID;
}
else
{
$Tra_Sch_Ids=$Tra_Sch_Ids.",".$S_ID;
}
}
}
	if($oper=="<")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<$array[2])
{
if(empty($Tra_Sch_Ids))
{
$Tra_Sch_Ids=$S_ID;
}
else
{
$Tra_Sch_Ids=$Tra_Sch_Ids.",".$S_ID;
}
}
}
}
if($oper=="<=")
{
if($Sum_Id<=0&&$array[2]>0)
{
}
else
{
if($Sum_Id<=$array[2])
{
if(empty($Tra_Sch_Ids))
{
$Tra_Sch_Ids=$S_ID;
}
else
{
$Tra_Sch_Ids=$Tra_Sch_Ids.",".$S_ID;
}
}
}
}
	if($oper=="=")
{
if($Sum_Id==$array[2])
{
if(empty($Tra_Sch_Ids))
{
$Tra_Sch_Ids=$S_ID;
}
else
{
$Tra_Sch_Ids=$Tra_Sch_Ids.",".$S_ID;
}
}
}
}
}
}
$R_Tra_Sch_Ids=explode(",",$Tra_Sch_Ids);
$nc=count($R_Tra_Sch_Ids);
$param1=$Tra_Sch_Ids.",School Id";
$param2=$Tra_Id.",Training Id,training_details";
$action="double";
}
}
}

 if($nc>5)
	  {
	  $hint='<div style="width:568px; height:450px; overflow-x:scroll; overflow-y:scroll;">';
	  }
	 if($nc!=0)
	{
	$hint=$hint.'<table border="1" class="tablefontv" align="left">';
	  $hint=$hint.'<tr bgcolor="#6AB5FF">';
	  if(!empty($R_La_Ids))
		{
		 $hint=$hint.'<td>Lab Type</td><td>School</td><td>Total number of '.$equ.'s</td><td width="180"></td></tr>';
			 for($i=0;$i<count($R_La_Ids);$i++)
		  {
		  $sch_na=mysql_query("SELECT * FROM school WHERE School_Id='".$R_Schoo_Ids[$i]."'");
		  if($r_sch=mysql_fetch_array($sch_na))
		  {
		  $R_Schoo_Name=$r_sch['Name'];
		  }
		  $Lab_type=mysql_query("SELECT * FROM lab WHERE Lab_Id='".$R_La_Ids[$i]."'AND School_Id='".$R_Schoo_Ids[$i]."'");
		  if($r_Lab_type=mysql_fetch_array($Lab_type))
		  {
		  $R_Lab_type=$r_Lab_type['Lab_Type'];
		  }
		  $Res_type=mysql_query("SELECT * FROM resource WHERE Resource_Type='".$equ."'");
		  if($r_Res_type=mysql_fetch_array($Res_type))
		  {
		  $R_Res_Id=$r_Res_type['Resource_Id'];
		  }
		  $t_equ=mysql_query("SELECT COUNT(Resource_Id) AS tot FROM resource_details WHERE School_Id='".$R_Schoo_Ids[$i]."' AND Lab_Id='".$R_La_Ids[$i]."' AND Resource_Id='".$R_Res_Id."'");
		  if($r_equ=mysql_fetch_array($t_equ))
		  {
		  $tot_equi=$r_equ['tot'];
		  }
			$hint=$hint.'<tr bgcolor="#999999"><td>'.$R_Lab_type.'</td><td>'.$R_Schoo_Name.'</td><td>'.$tot_equi.'</td><td width="80">';
 if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="triple")
{
$p1=explode(",",$param1);
	 $tn1=count($p1);
	 $paramf1=$R_La_Ids[$i].",".$p1[$tn1-1];	 
$p3=explode(",",$param2);
	 $tn3=count($p3);
	 $paramf3=$R_Res_Id.",".$p3[$tn3-1];
	  $p3=explode(",",$param3);
	 $tn2=count($p3);
	 $paramf2=$R_Schoo_Ids[$i].",".$p3[$tn2-2].",".$p3[$tn2-1];
	 if($tot_equi==0)
	 {	 
	 $paramf2=$R_Schoo_Ids[$i].",".$p3[$tn2-2].",lab";
	 $hint=$hint.'<a href="Printpageadv.php?action=double&p='.$paramf1.'&q='.$paramf2.'" target="_blank">';
	 }
	 else
	 {
  	  $hint=$hint.'<a href="Printpageadv.php?action=triple&p='.$paramf1.'&q='.$paramf3.'&r='.$paramf2.'" target="_blank">';
   	 }
	  }
	    $hint=$hint.'View more details</a></td></tr>';
		  }
		   if($R_La_Ids[0]=="")
		 {
		  $hint='<br/><br/><br/>';
		 }
		}
		
		if(!empty($Tea_Nics))
		{
		 $hint=$hint."<td>Teacher's name</td><td width='180'></td></tr>";
		  		  for($i=0;$i<count($Tea_Nics);$i++)
		  {
		  $T_name=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='".$Tea_Nics[$i]."'");
		  if($r_T_name=mysql_fetch_array($T_name))
		  {
		  $Tea_name=$r_T_name['First_Name']." ".$r_T_name['Last_Name'];
		  }
			$hint=$hint.'<tr bgcolor="#999999"><td>'.$Tea_name.'</td><td width="180">';
	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="single")
{
	  $p1=explode(",",$param);
	 $tn1=count($p1);
	 $paramf1=$Tea_Nics[$i].",".$p1[$tn1-2].",".$p1[$tn1-1];
    	   $hint=$hint.'<a href="Printpageadv.php?action=single&q='.$paramf1.'" target="_blank">';
   	 
	  }
	  	   $hint=$hint.'View more details</a></td></tr>';
		  }
		  if($Tea_Nics[0]=="")
		 {
		 $hint='<br/><br/><br/>';
		 }
		}
		
		if(!empty($Teac_Nics))
		{
		 $hint=$hint."<td>Teacher's Name</td><td width='100'>Training Name</td><td width='180'></td></tr>";
		  for($i=0;$i<count($Teac_Nics);$i++)
		  {
		  $T_Name=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='".$Teac_Nics[$i]."'");
		  if($r_T_Name=mysql_fetch_array($T_Name))
		  {
		  $Tea_Name=$r_T_Name['First_Name']." ".$r_T_Name['Last_Name'];
		  }
		  $Tra_name=mysql_query("SELECT * FROM training WHERE Training_Id='".$Trai_Id[$i]."'");
		  if($r_Tra_name=mysql_fetch_array($Tra_name))
		  {
		  $R_Tra_name=$r_Tra_name['Training_Name'];
		  }
			$hint=$hint.'<tr bgcolor="#999999"><td>'.$Tea_Name.'</td><td>'.$R_Tra_name.'</td><td width="180">';
	 	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="double")
{
$p1=explode(",",$param1);
	 $tn1=count($p1);
	 $paramf1=$Teac_Nics[$i].",".$p1[$tn1-1];
	 
	  $p2=explode(",",$param2);
	 $tn2=count($p2);
	 $paramf2=$Trai_Id[$i].",".$p2[$tn2-2].",".$p2[$tn2-1];
    	   $hint=$hint.'<a href="Printpageadv.php?action=double&p='.$paramf1.'&q='.$paramf2.'" target="_blank">';
   	  
	  }
	   $hint=$hint.'View more details</a></td></tr>';
		  }
		  if($Teac_Nics[0]=="")
		 {
		 $hint='<br/><br/><br/>';
		 }
		}
		
		 if(!empty($Pro_Ids))
		{
		 $hint=$hint.'<td width="100">Programme Name</td><td width="100">School</td><td width="180"></td></tr>';
		  		  for($i=0;$i<count($Pro_Ids);$i++)
		  {
		  $sch_na=mysql_query("SELECT * FROM school WHERE School_Id='".$Psch_Ids[$i]."'");
		  if($r_sch=mysql_fetch_array($sch_na))
		  {
		  $R_Schoo_Name=$r_sch['Name'];
		  }
		  $Pro_name=mysql_query("SELECT * FROM programme WHERE Programme_Id='".$Pro_Ids[$i]."'");
		  if($r_Pro_name=mysql_fetch_array($Pro_name))
		  {
		  $R_Pro_name=$r_Pro_name['Programme_Name'];
		  }
			$hint=$hint.'<tr bgcolor="#999999"><td>'.$R_Pro_name.'</td><td>'.$R_Schoo_Name.'</td><td width="180">';
	  	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="double")
{
$p1=explode(",",$param1);
	 $tn1=count($p1);
	 $paramf1=$Pro_Ids[$i].",".$p1[$tn1-1];

	    $p2=explode(",",$param2);
	 $tn2=count($p2);
	 $paramf2=$Psch_Ids[$i].",".$p2[$tn2-2].",".$p2[$tn2-1];
    	   $hint=$hint.'<a href="Printpageadv.php?action=double&p='.$paramf1.'&q='.$paramf2.'" target="_blank">';
   	  
	  }
	   $hint=$hint.'View more details</a></td></tr>';
		  }
		  if($Pro_Ids[0]=="")
		 {
		 $hint='<br/><br/><br/>';
		 }
		}
		
		 if(!empty($CSchoo_Ids))
		{
		 $hint=$hint.'<td width="100">School</td><td width="100">Number of times</td><td width="180"></td></tr>';
		 		  for($i=0;$i<count($CSchoo_Ids);$i++)
		  {
		  $tim=$Timesc[$i];
		  $sch_na=mysql_query("SELECT * FROM school WHERE School_Id='".$CSchoo_Ids[$i]."'");
		  if($r_sch=mysql_fetch_array($sch_na))
		  {
		  $R_Schoo_Name=$r_sch['Name'];
		  }		  
		  $hint=$hint.'<tr bgcolor="#999999"><td>'.$R_Schoo_Name.'</td><td>'.$tim.'</td><td width="180">';
	 
	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="double")
{
$p1=explode(",",$param1);
	 $tn1=count($p1);
	 $paramf1=$CSchoo_Ids[$i].",".$p1[$tn1-1];

	   $p2=explode(",",$param2);
	 $tn2=count($p2);
	 $paramf2=$tim.",".$p2[$tn2-2].",".$p2[$tn2-1];
    	   $hint=$hint.'<a href="Printpageadv.php?action=double&p='.$paramf1.'&q='.$paramf2.'" target="_blank">';
   	  
	  }
	   $hint=$hint.'View more details</a></td></tr>';
		  }
		   if($CSchoo_Ids[0]=="")
		 {
		 $hint='<br/><br/><br/>';
		 }
		}
		  ////
		if(!empty($R_Zones))
		{
		$p2=explode(",",$param2);
		 $hint=$hint.'<td width="100">Zone</td><td width="100">Number of '.$p2[0].' schools</td><td width="180"></td></tr>';
		 	for($i=0;$i<count($R_Zones);$i++)
		  {
		  $num_times=mysql_query("SELECT COUNT(School_Id) AS times FROM school WHERE Zone='".$R_Zones[$i]."' AND ".$p2[1]."='".$p2[0]."'");
		  if($r_num_times=mysql_fetch_array($num_times))
		  {
		  $tim=$r_num_times['times'];
		  }
		  $hint=$hint.'<tr bgcolor="#999999"><td>'.$R_Zones[$i].'</td><td>'.$tim.'</td><td width="180">';
	 
	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="double")
{
$p1=explode(",",$param1);
	 $tn1=count($p1);
	 $paramf1=$R_Zones[$i].",".$p1[$tn1-1];

	   $p2=explode(",",$param2);
	 $tn2=count($p2);
	 //$paramf2=$p2[0].",".$p2[$tn2-2].",".$p2[$tn2-1];
    	   $hint=$hint.'<a href="Printpageadv.php?action=double&p='.$paramf1.'&q='.$param2.'" target="_blank">';
   	  
	  }
	   $hint=$hint.'View more details</a></td></tr>';
		  }
		   if($R_Zones[0]=="")
		 {
		 $hint='<br/><br/><br/>';
		 }
		}
		  
		   if(!empty($R_Lab_Sch_Ids))
		{
		$p2=explode(",",$param2);
		 $hint=$hint.'<td width="100">School</td><td width="100">Number of '.$p2[0].'s</td><td width="180"></td></tr>';
		 	for($i=0;$i<count($R_Lab_Sch_Ids);$i++)
		  {
		  $num_times=mysql_query("SELECT COUNT(School_Id) AS times FROM lab WHERE School_Id='".$R_Lab_Sch_Ids[$i]."' AND ".str_replace(" ","_",$p2[1])."='".$p2[0]."'");
		  if($r_num_times=mysql_fetch_array($num_times))
		  {
		  $tim=$r_num_times['times'];
		  }
		  $sch_na=mysql_query("SELECT * FROM school WHERE School_Id='".$R_Lab_Sch_Ids[$i]."'");
		  if($r_sch=mysql_fetch_array($sch_na))
		  {
		  $School_Name=$r_sch['Name'];
		  }	
		  $hint=$hint.'<tr bgcolor="#999999"><td>'.$School_Name.'</td><td>'.$tim.'</td><td width="180">';
	 
	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="double")
{
$p1=explode(",",$param1);
	 $tn1=count($p1);
	 $paramf1=$R_Lab_Sch_Ids[$i].",".$p1[$tn1-1];

	   $p2=explode(",",$param2);
	 $tn2=count($p2);
	 //$paramf2=$p2[0].",".$p2[$tn2-2].",".$p2[$tn2-1];
    	   $hint=$hint.'<a href="Printpageadv.php?action=double&p='.$paramf1.'&q='.$param2.'" target="_blank">';
   	  
	  }
	   $hint=$hint.'View more details</a></td></tr>';
		  }
		   if($R_Lab_Sch_Ids[0]=="")
		 {
		 $hint='<br/><br/><br/>';
		 }
		}
			if(!empty($R_Tra_Sch_Ids))
		{
		$p2=explode(",",$param2);
		$tra_na=mysql_query("SELECT * FROM training WHERE Training_Id='".$p2[0]."'");
		  if($r_tra_na=mysql_fetch_array($tra_na))
		  {
		  $Training_Name=$r_tra_na['Training_Name'];
		  }	
		 $hint=$hint.'<td width="100">School</td><td width="100">Number of '.$Training_Name.' trained teachers</td><td width="180"></td></tr>';
		 	for($i=0;$i<count($R_Tra_Sch_Ids);$i++)
{
$All_Teacher_NIC="";
$all_schs=mysql_query("SELECT T_NIC_Number FROM teacher WHERE School_Id='".$R_Tra_Sch_Ids[$i]."'");
while($row_all_schs=mysql_fetch_array($all_schs))
{
if(empty($All_Teacher_NIC))
{
$All_Teacher_NIC="'".$row_all_schs['T_NIC_Number']."'";
}
else
{
$All_Teacher_NIC=$All_Teacher_NIC.",'".$row_all_schs['T_NIC_Number']."'";
}
}
		 $num_times=mysql_query("SELECT COUNT(Teacher_NIC) As times FROM training_details WHERE Teacher_NIC IN(".$All_Teacher_NIC.") AND Training_Id='".$p2[0]."'");
		  if($r_num_times=mysql_fetch_array($num_times))
		  {
		  $tim=$r_num_times['times'];
		  }
		  $sch_na=mysql_query("SELECT * FROM school WHERE School_Id='".$R_Tra_Sch_Ids[$i]."'");
		  if($r_sch=mysql_fetch_array($sch_na))
		  {
		  $School_Name=$r_sch['Name'];
		  }	
		  $hint=$hint.'<tr bgcolor="#999999"><td>'.$School_Name.'</td><td>'.$tim.'</td><td width="180">';
	 
	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="double")
{
	 $param=$All_Teacher_NIC.",Teacher NIC,training_details";
    $hint=$hint.'<a href="Printpageadv.php?action=single&q='.$param.'" target="_blank">';
   	  
	  }
	   $hint=$hint.'View more details</a></td></tr>';
		  }
		   if($R_Tra_Sch_Ids[0]=="")
		 {
		 $hint='<br/><br/><br/>';
		 }
		}
		if(!empty($R_S_In_Sch_Ids))
		{
		$p2=explode(",",$param2);
		 $hint=$hint.'<td width="100">School</td><td width="100">Number of '.$p2[0].' specialised teachers</td><td width="180"></td></tr>';
		 	for($i=0;$i<count($R_S_In_Sch_Ids);$i++)
		  {
$num_times=mysql_query("SELECT COUNT(Teacher_NIC) As times FROM teacher WHERE School_Id='".$R_S_In_Sch_Ids[$i]."' AND Specialised_In='".$p2[0]."'");
		  if($r_num_times=mysql_fetch_array($num_times))
		  {
		  $tim=$r_num_times['times'];
		  }
		  $sch_na=mysql_query("SELECT * FROM school WHERE School_Id='".$R_S_In_Sch_Ids[$i]."'");
		  if($r_sch=mysql_fetch_array($sch_na))
		  {
		  $School_Name=$r_sch['Name'];
		  }	
		  $hint=$hint.'<tr bgcolor="#999999"><td>'.$School_Name.'</td><td>'.$tim.'</td><td width="180">';
	 
	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="double")
{
$p1=explode(",",$param1);
	 $tn1=count($p1);
	 $paramf1=$R_S_In_Sch_Ids[$i].",".$p1[$tn1-1];

	   $p2=explode(",",$param2);
	 $tn2=count($p2);
	 //$paramf2=$p2[0].",".$p2[$tn2-2].",".$p2[$tn2-1];
    	   $hint=$hint.'<a href="Printpageadv.php?action=double&p='.$paramf1.'&q='.$param2.'" target="_blank">';
   	  
	  }
	   $hint=$hint.'View more details</a></td></tr>';
		  }
		   if($R_S_In_Sch_Ids[0]=="")
		 {
		 $hint='<br/><br/><br/>';
		 }
		}		

		 
		  ///
		 if(!empty($Schoo_Ids))
		{
		 $hint=$hint.'<td>School</td><td>Total number of labs</td><td width="180"></td></tr>';
		 	for($i=0;$i<count($Schoo_Ids);$i++)
		  {
		    $sch_na=mysql_query("SELECT * FROM school WHERE School_Id='".$Schoo_Ids[$i]."'");
		  if($r_sch=mysql_fetch_array($sch_na))
		  {
		  $R_Schoo_Name=$r_sch['Name'];
		  }
		  $t_labs=mysql_query("SELECT COUNT(Lab_Id) AS total_labs FROM lab WHERE School_Id='".$Schoo_Ids[$i]."'");
		  if($r_t_labs=mysql_fetch_array($t_labs))
		  {
		  $Tot_Labs=$r_t_labs['total_labs'];
		  }
			$hint=$hint.'<tr bgcolor="#999999"><td>'.$R_Schoo_Name.'</td><td>'.$Tot_Labs.'</td><td width="180">';
	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="single")
{
	 $p1=explode(",",$param);
	 $tn1=count($p1);
	 $paramf1=$Schoo_Ids[$i].",".$p1[$tn1-2].",".$p1[$tn1-1];
	  if($tota_tea==0)
	 {	 
	 $paramf1=$Schoo_Ids[$i].",".$p1[$tn1-2].",school";
	 $hint=$hint.'<a href="Printpageadv.php?action=single&q='.$paramf1.'" target="_blank">';
	 }
	 else
	 {
    	   $hint=$hint.'<a href="Printpageadv.php?action=single&q='.$paramf1.'" target="_blank">';
		   }
   	 
	  }
	   	   $hint=$hint.'View more details</a></td></tr>';
		  }
		  if($Schoo_Ids[0]=="")
		 {
		 $hint='<br/><br/><br/>';
		 }
		}
		
		 if(!empty($Stud))
		{
		 $hint=$hint.'<td>School</td><td width="180"></td></tr>';
		 		  for($i=0;$i<count($Stud);$i++)
		  {
		  $sch_na=mysql_query("SELECT * FROM school WHERE School_Id='".$Stud[$i]."'");
		  if($r_sch=mysql_fetch_array($sch_na))
		  {
		  $R_Schoo_Name=$r_sch['Name'];
		  }
			$hint=$hint.'<tr bgcolor="#999999"><td>'.$R_Schoo_Name.'</td><td width="180">';
	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="single")
{
	  $p1=explode(",",$param);
	 $tn1=count($p1);
	 $paramf1=$Stud[$i].",".$p1[$tn1-2].",".$p1[$tn1-1];
    	   $hint=$hint.'<a href="Printpageadv.php?action=single&q='.$paramf1.'" target="_blank">';
   	 
	  }
	  	   $hint=$hint.'View more details</a></td></tr>';
		  }
		  if($Stud[0]=="")
		 {
		 $hint='<br/><br/><br/>';
		 }
		}
		
		if(!empty($A_Subs))
		{
		 $hint=$hint.'<td>School</td><td>Total number of '.$app_s.' teachers</td><td width="180"></td></tr>';
				for($i=0;$i<count($A_Subs);$i++)
		  {
		  $sch_na=mysql_query("SELECT * FROM school WHERE School_Id='".$A_Subs[$i]."'");
		  if($r_sch=mysql_fetch_array($sch_na))
		  {
		  $R_Schoo_Name=$r_sch['Name'];
		  }
		  $t_tea=mysql_query("SELECT COUNT(T_NIC_Number) AS tot_tea FROM teacher WHERE School_Id='".$A_Subs[$i]."' AND Appointed_Subject='".$app_s."'");
		  if($r_t_tea=mysql_fetch_array($t_tea))
		  {
		  $tota_tea=$r_t_tea['tot_tea'];
		  }
			$hint=$hint.'<tr bgcolor="#999999"><td>'.$R_Schoo_Name.'</td><td>'.$tota_tea.'</td><td width="180">';
	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="double")
{
	 $p1=explode(",",$param);
	 $tn1=count($p1);
	 $paramf2=$A_Subs[$i].",".$p1[$tn1-2].",".$p1[$tn1-1];
	 $paramf1=$app_s.",Appointed Subject";
	 if($tota_tea==0)
	 {	 
	 $paramf2=$A_Subs[$i].",".$p1[$tn1-2].",school";
	 $hint=$hint.'<a href="Printpageadv.php?action=single&q='.$paramf2.'" target="_blank">';
	 }
	 else
	 {
    	   $hint=$hint.'<a href="Printpageadv.php?action=double&p='.$paramf1.'&q='.$paramf2.'" target="_blank">';
	 }
   	 
	  }
	   	   $hint=$hint.'View more details</a></td></tr>';
		  }
		   if($A_Subs[0]=="")
		 {
		 $hint='<br/><br/><br/>';
		 }
		}	 
		
			$hint=$hint.'</table>';
	}
			   if($nc>5)
	  {
	  $hint=$hint.'</div>';
	  }
	   ?>
	  <br/>
	  <?php
	  if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="single")
{
	  ?>
    	   <br/><a href="Printpageadv.php?action=single&q=<?php echo $param; ?>" target="_blank"><input type="button" name="print" class="print" value=""/></a>
   	  <?php
	  }
	   if($hint!='<br/><br/><br/>'&&$hint!='<br/><br/><br/></table></div>'&&$hint!='<br/><br/><br/></table>'&&$action=="double")
{
	  ?>
    	   <br/><a href="Printpageadv.php?action=double&p=<?php echo $param1; ?>&q=<?php echo $param2; ?>" target="_blank"><input type="button" name="print" class="print" value=""/></a>
   	  <?php
	  }
}
$hints= explode(" ",$hint);
$s=$hints[count($hints)-1];
if($s!="<br/>")
{
$hint=$hint."<br/>";
}
if($hint=='<br/><br/><br/><br/>'||$hint=='<br/><br/><br/></table></div><br/>'||$hint=='<br/><br/><br/></table><br/>')
{
$response='<br/><br/><font class="err"><img src="images/alert.jpg" width="12" height="12"/> There are no results for your search!</font>';
}
else
{
$response=$hint;
}
echo $response;
?>